package cn.hr.controller;

import cn.hr.pojo.MissionType;
import cn.hr.pojo.SysRole;
import cn.hr.pojo.SysUser;
import cn.hr.service.MissionTypeService;
import cn.hr.service.SysUserService;
import cn.hr.service.impl.SysRoleService;
import cn.hr.utils.Constants;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户控制器
 *
 * @author MO
 */
@Controller
@RequestMapping("/sys/mission")
public class MissionTypeController {
    private Logger logger = LoggerFactory.getLogger(MissionTypeController.class);
    @Resource
    private MissionTypeService missionTypeService;
    private String meagess;

    /***
     * 按条件查询
     * @return
     */
    @RequestMapping("/showList")
    public String list(@RequestParam(value="pageIndex",required = false)String pageIndex,
                       @RequestParam(value = "name",required = false)String name,
                       @RequestParam(value = "typeId",required = false)String typeId, Model model){
        Map<String,Object> map = new HashMap<>();
        int index = 1;
        if (pageIndex!=null&&pageIndex!=""){
            index = Integer.parseInt(pageIndex);
        }
        if (name!=null&&name!=""){
            map.put("name",name);
            model.addAttribute("name",name);
        }
        if (typeId!=null&&typeId!=""){
            map.put("typeId",Integer.parseInt(typeId));
            model.addAttribute("typeId",typeId);
        }
        try {
            PageInfo<Map> pageInfo = missionTypeService.findListByCondition(map,index);
            model.addAttribute("pageInfo",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "missionType/showList";
    }

    @RequestMapping("/list")
    public String showList(){
        return "missionType/missionTypeList";
    }

    @RequestMapping("/dispose")
    public String dispose(@RequestParam("id")Integer id){
        try {
            MissionType missionType = missionTypeService.get(id);
            switch (missionType.getTypeId()){
                case 38:
                    meagess = "redirect:/salaryStandard/openUp/"+missionType.getTableId()+"/modify";
                    break;
                case 39:
                    meagess = "redirect:/payroll/openCrewList/"+missionType.getTableId()+"/modify";
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return meagess;
    }

}

